package com.iwayin.core.dao.like;

import java.util.List;

import com.iwayin.core.dao.BaseDAOImpl;
import com.iwayin.core.dataobject.LikeDO;

public class LikeDAOImpl extends BaseDAOImpl implements LikeDAO {

	@Override
	public Long addLike(LikeDO like) {
		return (Long) this.getSqlMapClientTemplate().insert("LikeDAO.addLike", like);
	}

	@Override
	public void deleteLike(LikeDO like) {
		this.getSqlMapClientTemplate().delete("LikeDAO.deleteLike", like);

	}

	@Override
	public boolean isLike(Long askId, Long myId) {
		LikeDO like = new LikeDO();
		like.setAskId(askId);
		like.setUserId(myId);
		Integer count = (Integer) this.getSqlMapClientTemplate().queryForObject("LikeDAO.findLike", like);
		if (count > 0) {
			return true;
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Long> findAskLikeUsers(LikeDO like) {
		return (List<Long>) executeQueryForList("LikeDAO.findAskLikeUsers", "LikeDAO.findAskLikeUsers.count", like);
	}

	@Override
	public Long getLikeCountByAskId(Long askId) {
		return (Long) queryForObject("LikeDAO.getLikeCountByAskId", askId);
	}
}
